import { deepStrictEqual, strictEqual } from 'assert';
import { Mock } from 'lite-ts-mock';
import { TreePSD } from 'psd';

import { Color, Label } from './cc';
import { ConverterBase } from './base';
import { LabelConverterBase } from './label-base';

class Self extends LabelConverterBase {
    public get typer() {
        return Label;
    }

    protected getName() {
        return 'name';
    }
}

describe('src/scene/service/converter/label-base.ts', () => {
    describe('.convert()', () => {
        it('ok', async () => {
            const mockTreePSD = new Mock<TreePSD>();
            const self = new Self(null as any, null as any, null as any, mockTreePSD.actual);

            mockTreePSD.expectReturn(
                r => r.export(),
                {
                    name: 'test',
                    text: {
                        font: {
                            colors: [
                                [1, 2, 3, 4]
                            ],
                            sizes: [5]
                        },
                        value: 6,
                    }
                }
            );

            Reflect.set(self, 'createNode', (arg: any) => {
                deepStrictEqual(arg, {
                    name: 'name'
                });
                return 'node';
            });

            const lbl = {
                color: null,
                fontSize: null as any,
                string: null as any,
            } as Label;
            Reflect.set(self, 'appendComponent', (arg: any, arg1: any) => {
                strictEqual(arg, Label);
                strictEqual(arg1, 'node');
                return lbl;
            });

            ConverterBase.getCcPropFunc = (arg: any) => {
                strictEqual(arg, Color.name);
                return Color;
            };

            const res = await self.convert();
            strictEqual(res, 'node');
            strictEqual(lbl.color.r, 1);
            strictEqual(lbl.color.g, 2);
            strictEqual(lbl.color.b, 3);
            strictEqual(lbl.color.a, 4);
            strictEqual(lbl.fontSize, 5);
            strictEqual(lbl.string, 6);
        });
    });
});